package com.icw.utility;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

@Component
public class EnvUtils implements InitializingBean {

	@Autowired
	private Environment env;

	private static Environment ENV;

	@Override
	public void afterPropertiesSet() throws Exception {
		ENV = this.env;
	}

	public static String getActive() {
		return IcwUtils.ifNull(ENV.getProperty("spring.profiles.active"), () -> "dev");
	}

	private static boolean isStaging() {
		return getActive().equals("staging");
	}

	private static boolean isTesting() {
		return getActive().equals("tst");
	}

	public static boolean isProd() {
		return getActive().equals("prod");
	}

	public static boolean isDev() {
		return !(isProd() || isStaging() || isTesting());
	}
}
